package org.jeecg.modules.friendlyLink.controller;

import java.util.Arrays;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.friendlyLink.entity.GwFriendlyLink;
import org.jeecg.modules.friendlyLink.service.IGwFriendlyLinkService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

 /**
 * @Description: 友情链接
 * @Author: jeecg-boot
 * @Date:   2024-07-10
 * @Version: V1.0
 */
@Api(tags="友情链接")
@RestController
@RequestMapping("/friendlyLink/gwFriendlyLink")
@Slf4j
public class GwFriendlyLinkController extends JeecgController<GwFriendlyLink, IGwFriendlyLinkService> {

	@ApiOperation(value="友情链接-分页列表查询", notes="友情链接-分页列表查询")
	@GetMapping(value = "/list")
	public Result<IPage<GwFriendlyLink>> queryPageList(GwFriendlyLink gwFirm,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<GwFriendlyLink> queryWrapper = QueryGenerator.initQueryWrapper(gwFirm, req.getParameterMap());
		Page<GwFriendlyLink> page = new Page<>(pageNo, pageSize);
		IPage<GwFriendlyLink> pageList = service.page(page, queryWrapper);
		return Result.OK(pageList);
	}

	@AutoLog(value = "友情链接-添加")
	@ApiOperation(value="友情链接-添加", notes="友情链接-添加")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody GwFriendlyLink gwFirm) {
		service.save(gwFirm);
		return Result.OK("添加成功！", gwFirm.getId());
	}

	@AutoLog(value = "友情链接-编辑")
	@ApiOperation(value="友情链接-编辑", notes="友情链接-编辑")
	//@RequiresPermissions("org.jeecg.modules:gw_firm:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody GwFriendlyLink gwFirm) {
		service.updateById(gwFirm);
		return Result.OK("编辑成功!");
	}

	@AutoLog(value = "友情链接-通过id删除")
	@ApiOperation(value="友情链接-通过id删除", notes="友情链接-通过id删除")
	//@RequiresPermissions("org.jeecg.modules:gw_firm:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id") String id) {
		service.removeById(id);
		return Result.OK("删除成功!");
	}

	@AutoLog(value = "友情链接-批量删除")
	@ApiOperation(value="友情链接-批量删除", notes="友情链接-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids") String ids) {
		this.service.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

	@ApiOperation(value="友情链接-通过id查询", notes="友情链接-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<GwFriendlyLink> queryById(@RequestParam(name="id") String id) {
		GwFriendlyLink gwFirm = service.getById(id);
		if(gwFirm==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(gwFirm);
	}

    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, GwFriendlyLink gwFirm) {
        return super.exportXls(request, gwFirm, GwFriendlyLink.class, "友情链接");
    }

    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, GwFriendlyLink.class);
    }

}
